import request from "@/utils/request";
import {DictSonFormType, DictSonTableType} from "@/api/sys/admin/dict-son/types";
import {PATH_SYS_ADMIN} from "@/utils/constant";

const baseUrl = PATH_SYS_ADMIN + '/dict-son/'

/**
 * 通过字典id获取字典信息
 * @param id
 */
export function getDictSonByIdApi(id: number): Promise<DictSonFormType> {
    return request.get(baseUrl + id)
}

/**
 * 修改字典
 * @param id
 * @param data
 */
export function editDictSonApi(id: number, data: DictSonFormType): Promise<any> {
    return request.patch(baseUrl + id, data)

}

/**
 * 添加字典
 * @param dictId
 * @param data
 */
export function addDictSonApi(dictId: number, data: DictSonFormType): Promise<any> {
    return request.post(baseUrl + dictId, data)

}

/**
 * 删除字典
 * @param id
 */
export function deleteDictSonApi(id: number): Promise<any> {
    return request.delete(baseUrl + id)
}


/**
 * 通过父字典获取子字典列表
 * @param dictId
 * @param pageQuery
 */
export function getDictSonsByDictIdApi(dictId: number, pageQuery: PageQuery<DictSonTableType>): PromisePageListType<DictSonTableType> {
    return request.post(baseUrl + 'list/' + dictId, pageQuery)
}
